import processing.serial.*;


Serial myPort;

int COLS = 20;
int ROWS = 2;
int LINES = 0;

int[][] line; 

boolean isPrinting = false;
PImage img;

void setup(){






  myPort = new Serial(this, Serial.list()[0], 19200);
  println(Serial.list());
  img = loadImage("chucktxt2.png");
  LINES = img.height / 16;

  line = new int[LINES][640];

  for(int l = 0; l < LINES; l++){

    int arrayIndex = 0;

    int length = COLS * ROWS * LINES;

    print("byte line["+length+"] = {");
    for(int r = 0; r<ROWS; r++){
      for(int c = 0; c<COLS; c++){

        for(int ir=0; ir<8; ir++){
          int bp1 = 0;
          int bp2 = 0;


          for(int ic=0; ic<8; ic++){
            color p = img.get(c*8+ic, r*8+ir+l*16);
            if(red(p) >128) {
              bp1 += 1 << (7-ic);
            }
            bp2 = bp1;
          } 





          line[l][arrayIndex ] = (int)bp1;

          arrayIndex++;
          line[l][arrayIndex ] = (int)bp2;
          arrayIndex++;

          print(bp1+","+bp2+",");
        }
      } 
    }

  }

  println("}");
}


void draw(){

}

void print(){
  if(!isPrinting){
  isPrinting = true;


  println("send");

  for(int l = 0; l < LINES; l++){
    for(int i = 0; i< 640; i++){
      print(line[l][i]+",");
      myPort.write(line[l][i]); 
    } 
    delay(1800);
  }
  delay(5000);
  isPrinting = false;
  }
}

